using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Security;
using EqRepair.Code.Enums;
using EqRepair.Web;

namespace EqRepair.Code.Classes
{
	public static class Helper
	{
		static internal string CURRENT_USER_ROLE_KEY = "current_user_role";
		static internal string CURRENT_USER_ID_KEY = "current_user_id";
		static internal string CURRENT_USER_FULLNAME_KEY = "current_user_fullname";
		public static string GetHash(string input)
		{
			byte[] v = Encoding.Unicode.GetBytes(input);
			byte[] H = new SHA1CryptoServiceProvider().ComputeHash(v);

			string pH = "";
			foreach (byte b in H)
			{
				pH += b.ToString("X2");
			}
			return pH;
		}

		public static bool IsAccesToView(EmployeeRole? er, int pageCode)
		{
			List<PageAccessor> f=new List<PageAccessor>();
			f.Add(new PageAccessor(EmployeeRole.Administrator,1));
			f.Add(new PageAccessor(EmployeeRole.Administrator, 2));
			f.Add(new PageAccessor(EmployeeRole.Administrator, 3));
			f.Add(new PageAccessor(EmployeeRole.Administrator, 4));
			
			if (er.Equals(null))
				er = EmployeeRole.No;
			foreach (var r in f)
			{
				if (r.em== er && r.pc== pageCode)
					return true;
			}
			return false;
		}

		public static bool IsAccesToViewUrl(EmployeeRole? er, string pageCode)
		{
			pageCode = pageCode.Split('?')[0];
			var AllP = new List<string>
			           	{
			           		"/Web/Default.aspx",
			           		"/Web/CompEQ.aspx",
			           		"/Web/EQ.aspx",
			           		"/Web/Org.aspx",
			           		"/Web/Users.aspx",
			           		"/Web/ManualReq.aspx",
			           		"/Web/EquipmentDetail.aspx",
			           		"/Web/ProcessRequest.aspx",
			           		"/Web/MyOrder.aspx",
			           		"/Web/ReportToRep.aspx",
							"/Web/ReportOrd.aspx"
							

			           	};



			List<PageAccessor> f = AllP.Select(t => new PageAccessor(EmployeeRole.Administrator, t)).ToList();
			foreach (var t in AllP)
			{
				//	f.Add(new PageAccessor(EmployeeRole.Chief,t));
			}

			f.Add(new PageAccessor(EmployeeRole.Worker, "/Web/MyOrder.aspx"));
			f.Add(new PageAccessor(EmployeeRole.Worker, "/Web/ReportToRep.aspx"));
			f.Add(new PageAccessor(EmployeeRole.Worker, "/Web/ReportOrd.aspx"));



			f.Add(new PageAccessor(EmployeeRole.Chief, "/Web/ReportOrd.aspx"));
			f.Add(new PageAccessor(EmployeeRole.Chief, "/Web/MyOrder.aspx"));
			f.Add(new PageAccessor(EmployeeRole.Chief, "/Web/ReportToRep.aspx"));
			f.Add(new PageAccessor(EmployeeRole.Chief, "/Web/ProcessRequest.aspx"));
			f.Add(new PageAccessor(EmployeeRole.Chief, "/Web/ManualReq.aspx"));
			f.Add(new PageAccessor(EmployeeRole.Chief, "/Web/CompEQ.aspx"));
			//f.Add(new PageAccessor(EmployeeRole.Chief, "/Web/EquipmentDetail.aspx"));
			//f.Add(new PageAccessor(EmployeeRole.Chief, "/Web/EQ.aspx"));



			if (er.Equals(null))
				er = EmployeeRole.No;
			return f.Any(r => r.em == er && r.pcs == pageCode);
		}
	}
}